package penuntze.filesystem

import penuntze.scan.ScanJob
import penuntze.scan.ScanThread;

class ScannerService {

    ScanJob scanFolder(String folderPath) {
		File folder = new File(folderPath)
		if (folder.exists() && folder.canRead() && folder.isDirectory()) {
			ScanJob scanJob = new ScanJob()
			ScanThread scanThread = new ScanThread(scanJob)
			scanJob.scanThread = scanThread
			scanJob.scanThread.start()
			return scanJob
		}
		else {
			log.error("Cannot access folder " + folderPath)
			return null
		}
	}
	
	boolean isScanJobRunning(ScanJob scanJob) {
		return scanJob.running
	}
}
